﻿using GreenPipes;
using MassTransit;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Config;
using NLog.Web;
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

public static class LogExtensions
{
    public static void AddGoLifeLog(this ILoggingBuilder loggingBuilder, IHostEnvironment hostEnvironment)
    {
        LoggingConfiguration loggingConfiguration = new LoggingConfiguration();

        var logfile = new NLog.Targets.FileTarget("logfile") { FileName = hostEnvironment.ContentRootPath + "/log/" + DateTime.Today.ToString("yyyyMMdd") + ".log" };
        var logconsole = new NLog.Targets.ConsoleTarget("logconsole");
        loggingConfiguration.AddRule(NLog.LogLevel.Trace, NLog.LogLevel.Fatal, logconsole);
        loggingConfiguration.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Fatal, logfile);
        loggingBuilder.AddNLog(loggingConfiguration);
    }
    public static void LogException(this ILogger logger,Exception ex,object data=null)
    {
        logger.LogError("系统发生异常 Message:{0} StackTrace:{1} Source:{2} ExceptionData:{3} Params:{4}", ex.Message, ex.StackTrace, ex.Source, ex.Data, data);
    }
}

